package com.zack.gank.gankandroid.main.find;

import com.gank.zack.ganklibrary.network.retrofit.RetrofitHelper;
import com.orhanobut.logger.Logger;
import com.zack.gank.gankandroid.api.GankInterface;
import com.zack.gank.gankandroid.main.find.FindSelectView;
import com.zack.gank.gankandroid.main.find.bean.AndroidGank;
import com.zack.gank.gankandroid.main.find.bean.ImageGank;
import com.zack.gank.gankandroid.main.find.bean.TodayGank;
import com.zack.gank.gankandroid.utils.InterfaceUtils;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Android on 2017/7/14.
 */
public class FindAndroidPresenter implements FindAndroidView.Presenter {

    FindAndroidView findView;
    public FindAndroidPresenter(FindAndroidView findView) {
        this.findView=findView;
    }


    @Override
    public void setGankNumPager(String type,String number, String pager) {
        GankInterface gankInterface= RetrofitHelper.createApi(GankInterface.class);
        getAndroidData(gankInterface,type,number,pager);
    }


    /**
     * 获取默认图片 在没有图片的情况下
     * @param gankInterface
     */
    private void getAndroidData(GankInterface gankInterface,String type,String number,String pager){
        Call<AndroidGank> objectCall=gankInterface.getGankData(type, number, pager);
        objectCall.enqueue(new Callback<AndroidGank>() {
            @Override
            public void onResponse(Call<AndroidGank> call, Response<AndroidGank> response) {
                Logger.v(response.body().toString());
                findView.onSucess(response.body());
            }

            @Override
            public void onFailure(Call<AndroidGank> call, Throwable t) {
                findView.onFile(t);
            }
        });
    }
}
